package dk.twu.analyzer.core;

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.TreeSet;

/**
 * Created by Tao Wu on 19/04/2015.
 */
public class MarketDuration {
    private TreeSet<LocalTime> timeUnits;

    public MarketDuration(LocalTime marketOpen, LocalTime marketClose, ChronoUnit timeUnit) {
        this.timeUnits = initTimeUnits(marketOpen, marketClose, timeUnit);
    }

    private TreeSet<LocalTime> initTimeUnits(LocalTime marketOpen, LocalTime marketClose, ChronoUnit timeUnit) {
        TreeSet timeUnits = new TreeSet();
        LocalTime curTime = marketOpen;
        while (curTime.isBefore(marketClose)) {
            timeUnits.add(curTime);
            curTime = curTime.plus(1, timeUnit);
        }
        return timeUnits;
    }

    public TreeSet<LocalTime> getTimeUnits() {
        return timeUnits;
    }

    public LocalTime getLastUnit() {
        return timeUnits.last();
    }

    public LocalTime getFirstUnit() {
        return timeUnits.first();
    }

}
